<template>
    <bi-form @submit="save">
        <bi-card>


            <bi-form-item label="关闭上传" >
                <bi-switch v-model="form.disabled" ></bi-switch>
            </bi-form-item>

            <bi-form-item label="目录类型" >
                <bi-select v-model="form.folder_type" :option="folderTypeOption" :clear="false" ></bi-select>
            </bi-form-item>



            <bi-form-item label="文件大小" >
                <bi-input v-model="form.file_size" type="number" >
                    <template #after>
                        <bi-select   handle-type="button"  v-model="form.file_size_unit"  :option="unitTypeOption" :clear="false" ></bi-select>
                    </template>
                </bi-input>
            </bi-form-item>

            <bi-form-item label="类型类型"  >
                <bi-list  @add="addFileType" @del="delFileType"  :data="form.file_type" v-slot="{index}"  >
                    <bi-input  v-model="form.file_type[index]" placeholder="文件扩展名，不用填写文件和扩展名之间的 ." />
                </bi-list>
            </bi-form-item>

            <template #footer>
                <bi-button type="primary" submit icon="fa-save"  >保存</bi-button>
            </template>
        </bi-card>
    </bi-form>
</template>


<script>
export default{
    data(){
        let form ={
                disabled:false,
                folder_type:'/YYYYMM/DD/',
                file_size:10,
                file_size_unit:'MB',
                file_type:['png']
        }

        form = this.$assign(form,this.$pageData.upload);
        
        let folderTypeOption = ['/YYYY/MM/DD/','/YYYYMM/DD/','/YYYYMMDD/HH'];
        let unitTypeOption = ['MB','KB'];
        
        return {
            folderTypeOption,
            unitTypeOption,
            form
        }
    },
    methods:{
        save(){
            this.$ajax({
                url:this.$url({action:'saveUpload'}),
                data:this.form,
                success:()=>{
                    this.$toast('保存成功');
                }
            });
        },
        addFileType(){
            this.form.file_type.push('');
        },
        delFileType(index){
            this.form.file_type.splice(index,1);
        }
    }
}
</script>